#ifndef DATAEXPORTDIALOG_H
#define DATAEXPORTDIALOG_H
#include <iostream>
#include <stdio.h>
#include <iostream>
#include <QtCore>
#include <QDebug>
#include <QCoreApplication>
#include <QObject>

#include <QDialog>
#include <QTextStream>
#include <QSqlTableModel>
#include <QFile>
#include <math.h>
#include <QSqlDatabase>
#include <QSqlTableModel>
#include <QSqlQuery>
#include <QSqlRecord>
#include <QSqlField>
#include <QtGui>
#include <QTextImageFormat>
#define LF QChar(0x0A)  /* '\n' */
#define CR QChar(0x0D)  /* '\r' */
#include "ui_dataexportdialog.h"


//
/*  Save file as dataexportdialog.h  */
/*  incomming class name DataExportDialog */
//   public QObject | public QHttp | public QThread                                    // 

class ModelConverter 
{

public:
 ModelConverter();
 ~ModelConverter();
 void set( const QAbstractItemModel  *in_model , bool style = true );
 void set( const QStandardItemModel  *in_model , bool style = true );
 void set( const QSqlQueryModel  *in_model );
 void set( QTableView  *table , bool style = true );
 void set( QTableWidget  *table , bool style = true );
 void increment( const int i );
 QTextDocument *TabletoDom( int remove_last_line = 0 );
 inline QStandardItemModel *get() { return model; }
 inline int lines() const  { return model->rowCount(); }
 void nulldata();
private:
    QStandardItem *Style( const QModelIndex index , const QString txt  , const int line );
    QStandardItemModel  *model;
    QStringList headers;
    int row;
    Qt::ItemFlags flags;
    QFont bold_base_font;
};



/*
 QWidget* parent , 
                                    QSqlQueryModel * q_model , 
                                    bool report ,
                                    QStandardItemModel * s_model
*/


//
class DataExportDialog : public QDialog, public Ui::DataExportDialog
{
     Q_OBJECT
//
public:
    
DataExportDialog( QWidget* parent , QSqlQueryModel * q_model , bool report = true , QStandardItemModel * s_model = new QStandardItemModel() );
bool header();
inline void SetTable( const QString  tab ) { tablename = tab; }
inline void SetDoc( QTextDocument * doc ) { Reports = doc; }   /* report bool DataExportDialog::exportReport() */
bool doExport();

bool exportCSV();
bool exportHTML();
bool exportExcelXML();
bool exportSql();
bool exportPython();
bool exportReport();

protected:
bool openStream();
QString celldata( const int line , const int cools );
bool GrepNummer ( QString data );
bool setProgress(int p);
QMap<QString,QString> formats;
QTextDocument *Reports;
QString endl();
QString tablename;
bool closeStream();
QString one;
int nummer;
QStringList list;
QUrl url;
QByteArray byteArray;
bool having;
void closeEvent( QCloseEvent* );
bool cancelled;
QStandardItemModel *m_data;
QStringList m_header;
QProgressDialog * progress;
QTextStream out;
QString clipboard;
QFile file;
bool exportFile;
private:
    QString StringtoXML( QString t );
    QString Stringtxt( QString t );
signals:
public slots:
    void fileButton_toggled(bool state);
    void searchButton_clicked();
    void cancel();

};
//
#endif // DATAEXPORTDIALOG_H




